package com.oocl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.oocl.dao.UserDao;
import com.oocl.pojo.Users;
import com.oocl.util.DBUtil;

public class UserDaoImpl implements UserDao{

	public List<Users> findAll() {
		String sql = "select * from users";
		List<Users> list = new ArrayList<Users>();
		Connection con = null;
		PreparedStatement stat =null;
		ResultSet rs = null;
        try {
        	con = DBUtil.createConnection();
			stat = con.prepareStatement(sql);
			rs = stat.executeQuery();
			while(rs.next()){
				System.out.println("1");
				Users user = new Users();
				user.setId(rs.getInt("id"));
				user.setName(rs.getString("name"));
				list.add(user);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			DBUtil.close(con, stat, rs);
			
		}
		return list;
	}


}
